|
OBJECT HIT
This command will return a one if the two specified 3D objects hit each other.
Return Integer=OBJECT HIT(ObjectA Number, ObjectB Number)
ObjectA Number
Integer
The object number
ObjectB Number
Integer
The second object number or zero to check all 3d objects
This command will return a one if the two specified 3D objects hit each other
If the second object number is set to zero, the number of the object hit by the first object will be returned as an integer value. The parameters should be specified using integer values. Spheres and boxes are solid objects, and so collision can only occur when they collide together. When an object is entirely within another object, even though the geometry is not touching, the collision is still valid as the larger object would be a solid construct. You cannot perform polygon to polygon collision on two objects. When two polygon objects are asked to test for collision, the secondary object will be treated like a sphere for collision purposes, where the outer extents of the objects geometry shall define the sphere.
sync on : sync rate 60 : hide mouse:cls 0
autocam off
set global collision on
ObjectNumber=1
SecondObject=2
make object sphere ObjectNumber,10
color object ObjectNumber,rgb(0,255,0)
position object ObjectNumber, 0,0,0
set object collision on ObjectNumber
make object cone secondObject,10
xrotate object secondObject,90
fix object pivot secondObject
color object SecondObject,rgb(255,0,0)
position object SecondObject, 15,0,0
set object collision off SecondObject
make object collision box ObjectNumber, -5,-5,-5,5,5,5,0
make object collision box SecondObject, -5,-5,-5,5,5,5,0
while mouseclick()=0
if leftkey()=1 then turn object left SecondObject,1
if rightkey()=1 then turn object right SecondObject,1
if upkey()=1 and OBJECT HIT(SecondObject,0)=0 then move object SecondObject,1
if downkey()=1 and OBJECT HIT(SecondObject,0)=0 then move object SecondObject,-1
if spacekey()=1 then move camera 0,1
if returnkey()=1 then position object SecondObject,15,0,0
if OBJECT COLLISION(SecondObject,0)
print "OBJECT COLLISION"
print "GET OBJECT COLLISION X",GET OBJECT COLLISION X()
print "GET OBJECT COLLISION Y",GET OBJECT COLLISION y()
print "GET OBJECT COLLISION Z",GET OBJECT COLLISION z()
print "OBJECT COLLISION CENTER X",OBJECT COLLISION CENTER X(ObjectNumber)
print "OBJECT COLLISION CENTER Y",OBJECT COLLISION CENTER Y(ObjectNumber)
print "OBJECT COLLISION CENTER Z",OBJECT COLLISION CENTER Z(ObjectNumber)
print "OBJECT COLLISION RADIUS",OBJECT COLLISION RADIUS(ObjectNumber)
endif
position camera object position x(SecondObject),object position y(SecondObject)+50,object position z(SecondObject)
point camera object position x(SecondObject),0,object position z(SecondObject)
sync
endwhile
delete object collision box ObjectNumber
delete object collision box SecondObject
set global collision off
delete object ObjectNumber
delete object SecondObject
end
BASIC3D Commands Menu
Index
|